home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / term / vltj5867.lha / VLT / rexx / VLTRequest.vlt < prev    next >
Text File  |  1994-03-27  |  6KB  |  201 lines

  1. /** VLTRequest.vlt
  2. *
  3. *   DESCRIPTION:
  4. *
  5. *   Puts up requester(s) and executes a command with the result.
  6. *
  7. *   CALLING SEQUENCE:
  8. *
  9. *   VLTRequest.vlt command, hail1, variable1, hail2, variable2, hail3, variable3
  10. *
  11. *   The commas are used as separators and must be present.
  12. *
  13. *   The "command" may contain sequences of the form [nxxx]
  14. *   where n is 1, 2, or 3, and x is a combination of letters. The first
  15. *   indicates what type of requester:
  16. *         f  file requester
  17. *         g  font requester
  18. *         s  string requester
  19. *         b  boolean requester
  20. *         d  no requester, use default as retrieved from variables.
  21. *   Any others may modify the requester type:
  22. *         s  "save" requester.
  23. *         d  directory requester.
  24. *   Modifiers that don't apply are ignored.
  25. *
  26. *   The hail1/2/3 strings are used for the requester(s) as hail strings.
  27. *
  28. *   The variable1/2/3 names are either the names of things that can be
  29. *   extracted from VLT using "extract", or they start with "vlt", in which
  30. *   case an environment variable of that name is created to keep track of
  31. *   of the default. If a [] sequence with the same number is used again,
  32. *   the result previously returned by the requester of that number is
  33. *   substituted.
  34. *
  35. *   EXAMPLE:
  36. *
  37. *        ~@VLTRequest.vlt (capture [1fs], Capture File Name:, CAPTUREFILE)
  38. *
  39. *   What this does is: it will bring up a file requester (with the SAVE flag),
  40. *   with the hailing string "Capture File Name:" and the default that's found
  41. *   by extracting CAPTUREFILE from VLT, and then if the user selects a file,
  42. *   it will substitute it instead of "[1fs]". It then issues the command
  43. *   "capture (filename)" to VLT. If there is no suitable thing to extract
  44. *   from VLT (CAPTUREFILE in the example), then you can use something that
  45. *   starts with "vlt", and it will create an env variable of that name and
  46. *   use that to keep track of the default. You can substitute up to 3
  47. *   requester results in the command by using 1, 2 or 3 as a first character
  48. *   between the []. You can open file requesters (f), font requesters (g),
  49. *   string requester (s) and boolean requesters (b), and the file requester
  50. *   can have options d (directory requester) and s ("save" requester). If you
  51. *   use the same number more than once in command, then whatever the result
  52. *   was for the requester that came up when that number was encountered first
  53. *   will be substituted. Of course, if you pop up more than one requester,
  54. *   you have to supply more commas and hail strings and extract variables.
  55. *   If you don't want to put up a requester but just the current default,
  56. *   you can use "d" as the "requester type".
  57. *
  58. *   By W.G.J. Langeveld, February 1992.
  59. *
  60. **/
  61. hail.   = ""
  62. envnam. = ""
  63.  
  64. parse arg cmd "," hail.1 "," envnam.1 "," hail.2 "," envnam.2 "," hail.3 "," envnam.3
  65.  
  66. cmd  = strip(cmd)
  67. do i = 1 to 3
  68.    hail.i   = strip(hail.i)
  69.    envnam.i = strip(envnam.i)
  70. end
  71. /*
  72. *   Add libraries if necessary
  73. */
  74. if show("l", "rexxarplib.library") = 0 then do
  75.    check = addlib('rexxsupport.library', 0, -30, 0)
  76.    check = addlib('rexxarplib.library',  0, -30, 0)
  77. end
  78. /*
  79. *   Determine VLT port and screen name and size
  80. */
  81. vltport = address()
  82. cols = ScreenCols(vltport)
  83. if cols == -1 then do
  84.    vltscreen = ""
  85.    cols = ScreenCols()
  86.    rows = ScreenRows()
  87. end
  88. else do
  89.    vltscreen = vltport
  90.    rows = ScreenRows(vltscreen)
  91. end
  92. /*
  93. *   Loop until no more [nxxx] sequences
  94. */
  95. k         = 0
  96. rn        = 0
  97. rt        = ""
  98. mf        = ""
  99. filename. = ""
  100.  
  101. do i = 0
  102.    k = index(cmd, "[", k + 1)
  103.    if k = 0 then leave
  104.    startinsert = k
  105. /*
  106. *   Find out which requester number, type and flags.
  107. */
  108.    k = k + 1
  109.    rn = upper(substr(cmd, k, 1))
  110.    k = k + 1
  111.    rt = upper(substr(cmd, k, 1))
  112.  
  113.    flags = ""
  114.    do j = 0
  115.       k = k + 1
  116.       mf = upper(substr(cmd, k, 1))
  117.       if      mf = "]" then leave
  118.       else if mf = "S" then flags = flags || "+SAVE"
  119.       else if mf = "G" then flags = flags || "+NOFILES"
  120.    end
  121.    endinsert = k
  122. /*
  123. *   Get the last stored value
  124. */
  125.    if substr(envnam.rn, 1, 3) = "VLT" then do
  126.       string = getenv(envnam.rn)
  127.       id = ""
  128.    end
  129.    else do
  130.       "extract "envnam.rn
  131.       id = envnam.rn
  132.       string = VLT.id
  133.    end
  134. /*
  135. *   If we had this requester number already, we can just use the
  136. *   file name we already had.
  137. */
  138.    if filename.rn = "" then do
  139. /*
  140. *   Now decide which kind of requester
  141. */
  142.       if rt = "D" then do
  143.          filename.rn = string
  144.       end
  145.       else if rt = "F" then do
  146.          filename = string
  147.          dirname  = ""
  148. /*
  149. *   Break up into file and dir
  150. */
  151.          nf = lastpos("/", filename)
  152.  
  153.          if nf = 0 then do
  154.             nf = lastpos(":", filename)
  155.             if nf ~= 0 then do
  156.                dirname  = substr(filename, 1, nf)
  157.                filename = substr(filename, nf + 1)
  158.             end
  159.          end
  160.          else do
  161.             dirname  = substr(filename, 1, nf - 1)
  162.             filename = substr(filename, nf + 1)
  163.          end
  164. /*
  165. *   Find out which entry
  166. */
  167.          filename.rn = GetFile(80, 50, dirname, filename, hail.rn, vltscreen, flags)
  168.       end
  169.       else if rt = "G" then do
  170.          fontname    = string
  171.          filename.rn = GetFont(80, 50, fontname, 8, hail.rn, vltscreen, FIXEDWIDTH, fontstem, 8, 11)
  172.       end
  173.       else if rt = "S" then do
  174.          filename.rn = Request(80, 50, hail.rn, string, " Okay ", "Cancel", vltscreen)
  175.       end
  176.       else if rt = "B" then do
  177.          filename.rn = Request(80, 50, hail.rn,, " Yes ", "  No ", vltscreen)
  178.          if filename.rn = "OKAY" then filename.rn = "1"
  179.          else                         filename.rn = "0"
  180.       end
  181.  
  182.       if filename.rn = "" then exit
  183. /*
  184. *   Set the file name for next time (only for env vars).
  185. */
  186.       if id = "" then call setenv(envnam.rn, filename.rn)
  187.    end
  188. /*
  189. *   substitute the filename in the command
  190. */
  191.    first = substr(cmd, 1, startinsert - 1)
  192.    last  = substr(cmd, endinsert + 1)
  193.    cmd = first || " ("filename.rn") " || last
  194. end
  195. /*
  196. *   Execute the command
  197. */
  198. ""cmd
  199.  
  200. exit
  201.